package mest.controller.Modeling;

import com.alibaba.fastjson.JSON;
import mest.VO.Modeling.BomSaveFile_manytomany.savefileVO;
import mest.VO.Modeling.WorkrouteWork_manytomany.workVO;
import mest.entity.bomsave_manytomany;
import mest.entity.workroutework_manytomany;
import mest.service.Modeling.IbomService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import mest.entity.bom;
/**
 * @Description
 * @auther Machenike
 * @create 2019-11-15 22:41
 */
@RestController
@CrossOrigin
@RequestMapping(value = "/bom")
public class bomController {

    @Resource
    private IbomService ibomService;

    @RequestMapping(value="/insert")
    public String insert(mest.entity.bom wf ){

        int i = ibomService.insertBOMFile(wf);
        if (i >= 1)
            return JSON.toJSONString("添加成功");
        else
            return JSON.toJSONString("添加失败");
    }
    @RequestMapping(value = "/baseSelect", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public String baseSelect(int index,int pageSize) {

        List<mest.entity.bom> BOMPage = ibomService.findBOMFilePage(index, pageSize);
        int i = ibomService.selectCount();
        Map map  = new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",i);
        map.put("data",BOMPage);
        return JSON.toJSONString(map);
    }

    //    toolbar查看bom详情
    @RequestMapping(value="/saveFileDetail", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public String saveFileDetail(int bomid,int index,int pageSize){

        System.out.println(bomid);
        List<savefileVO> savefileByBOMId = ibomService.findSaveByBOMId(bomid,index,pageSize);
        int i = ibomService.SaveCount(bomid);
        Map map  = new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",i);
        map.put("data",savefileByBOMId);
        return JSON.toJSONString(map);
    }
    //    toolbar添加bom
    @RequestMapping(value="/addBom", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public String addBom(bomsave_manytomany bsmtm){

        int i = ibomService.insertManytomany_bomAndSave(bsmtm);
        if (i >= 1)
            return JSON.toJSONString("添加成功");
        else
            return JSON.toJSONString("添加失败");
    }


    // toolbar 修改bom
    @RequestMapping(value="/updateBom", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public String updateBom(savefileVO bsmtm){

        int i = ibomService.updateManytomany_bomAndSave(bsmtm);
        if (i >= 1)
            return JSON.toJSONString("修改成功");
        else
            return JSON.toJSONString("修改失败");
    }

}
